import { message } from 'antd';
let todoLists = [
    {
        id: 1,
        title: 'TodoList列表',
        state: 0,
    },
    {
        id: 2,
        title: 'TodoList添加',
        state: 1,
    },
    {
        id: 3,
        title: 'TodoList编辑',
        state: 2,
    },
    {
        id: 4,
        title: 'TodoList修改状态',
        state: 0,
    },
    {
        id: 5,
        title: 'TodoList列表',
        state: 0,
    },
    {
        id: 6,
        title: 'TodoList添加',
        state: 1,
    },
    {
        id: 7,
        title: 'TodoList编辑',
        state: 2,
    },
    {
        id: 8,
        title: 'TodoList修改状态',
        state: 0,
    },
]

export default {
    'GET /api/todolists':{
        success:'true',
        msg:'接口请求成功',
        data:todoLists
    },
    'POST /api/todo':(req: any,res: { send: (arg0: any) => void })=>{
        const item = {
            id:todoLists.length+1,
            title:req.body.todo,
            state:0
        }
        todoLists.unshift(item)
        // 返回添加结果
        const result = {
            state:201,
            message:'添加待办事项成功'
        }
        res.send(result)
    },
    'PUT /api/edit':(req: any,res: { send: (arg0: any) => void })=>{
        const {id,state} = req.body
        // 筛选todo,进行修改
        todoLists.map((item: { id: any; },index: string | number)=>{
    if(item.id===id) todoLists[index].state=state
})
        // 返回的结果
        res.send({
            code:0,
            message:'修改成功'
        })
    }
}